package com.itheima.controller;

import com.itheima.common.constant.MessageConstant;
import com.itheima.common.entity.Result;
import com.itheima.pojo.BusinessReportVO;
import com.itheima.pojo.MemberReportVO;
import com.itheima.pojo.SetmealReportVO;
import com.itheima.service.ReportService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;

@RestController
@RequestMapping("/report")
@Slf4j
public class ReportController {

    @Autowired
    private ReportService reportService;

    /**
     * 获取套餐占比统计数据
     * @return
     */
    @GetMapping("/getSetmealReport")
    public Result getSetmealReport(){
        log.info("获取套餐占比统计数据");
        SetmealReportVO setmealReportVO = reportService.getSetmealReport();
        return new Result(true, MessageConstant.GET_SETMEAL_COUNT_REPORT_SUCCESS, setmealReportVO);
    }

    /**
     * 获取会员数量统计数据
     * @return
     */
    @GetMapping("/getMemberReport")
    public Result getMemberReport(){
        log.info("获取会员数量统计数据");
        MemberReportVO memberReportVO = reportService.getMemberReport();
        return new Result(true, MessageConstant.GET_MEMBER_NUMBER_REPORT_SUCCESS, memberReportVO);
    }

    /**
     * 获取运营统计数据
     * @return
     */
    @GetMapping("/getBusinessReportData")
    public Result getBusinessReportData(){
        log.info("获取运营统计数据");
        BusinessReportVO businessReportVO = reportService.getBusinessReport();
        return new Result(true, MessageConstant.GET_BUSINESS_REPORT_SUCCESS, businessReportVO);
    }

    /**
     * 导出运营数据报表
     * @return
     */
    @GetMapping("/exportBusinessReport")
    public Result exportBusinessReport(HttpServletResponse response){
        log.info("导出运营数据报表");
        reportService.exportBusinessReport(response);
        return new Result(true, MessageConstant.GET_BUSINESS_REPORT_SUCCESS);
    }
}
